import java.net.URL;

import com.vmware.vim25.Event;
import com.vmware.vim25.EventFilterSpec;
import com.vmware.vim25.mo.EventHistoryCollector;
import com.vmware.vim25.mo.EventManager;
import com.vmware.vim25.mo.ServiceInstance;

public class EventHistoryCollectorMonitor 
{  
  public static void main(String[] args) throws Exception
  {
    
	String[] temp = new String[]{"https://10.16.2.59/sdk","root","vmware"};
	 
    ServiceInstance si = new ServiceInstance(new URL(temp[0]), 
        temp[1], temp[2], true);

    EventManager evtMgr = si.getEventManager();

    if(evtMgr!=null)
    {
      EventFilterSpec eventFilter = new EventFilterSpec();
      EventHistoryCollector ehc = 
        evtMgr.createCollectorForEvents(eventFilter);
      Event[] events = ehc.getLatestPage();

      for (int i = 0; i < events.length; i++)
      {
        Event anEvent = events[i];
        System.out.println("Event: " + 
            anEvent.getFullFormattedMessage());
      }
    }
    si.getServerConnection().logout();
  }
}